<template>
    <div>
        <input type="text" name="" v-model="page.hname" id="">
        <input type="button" value="查询" @click="show">
<a :href="'https://localhost:7167/api/Hospital/Get'">导出</a>
<table>
    <thead>
        <tr>
            <td>
                <input type="checkbox" name="" v-model="type" @click="all" id="">
            </td>
            <td>项目编号</td>
            <td>项目名称</td>
            <td>佣金</td>
            <td>状态</td>
            <td>人数</td>
            <td>时长</td>
            <td>操作</td>
        </tr>
    </thead>
    <tbody>
        <tr v-for="a in list">
            <td>
                <input type="checkbox" name="" v-model="ids" :value="a.hid"  id="">
            </td>
            <td>{{ a.number }}</td>
            <td>{{ a.hname }}</td>
            <td>{{ a.price }}</td>
            <td>{{ a.state?"启用":"禁用" }}</td>
            <td>{{ a.num }}</td>
            <td>{{ a.time }}</td>
            <td>
                <input type="button" value="删除" @click="del(a.hid)">
                <input type="button" v-if="a.state" value="批量启用" @click="state">
                <input type="button" v-else value="批量禁用" @click="state">

            </td>
        </tr>
    </tbody>
</table>
<input type="button" value="首页" @click="fan(1)">
<input type="button" value="上一页" @click="fan(2)">
<input type="button" value="下一页" @click="fan(3)">
<input type="button" value="尾页" @click="fan(4)">
共{{ count.count }}条 每页{{ page.pagehang }}条  共{{page.pagenow  }}/{{count.pagecount  }}页
<input type="text" name="" v-model="page.pagenow" id="">
<input type="button" value="跳转" @click="t">
<select v-model="page.pagehang" @click="t"> 
<option>2</option>
<option>4</option>
<option>5</option>
</select>

    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
const t=()=>{
    show()
}
const fan=(a:any)=>{
    if(a==1){
        page.value.pagenow=1;
        show()
    }
    if(a==2){
        if(page.value.pagenow>1){
            page.value.pagenow-=1;
            show()
        }
       
    }
    if(a==3){
        if(page.value.pagenow<count.value.pagecount){
            page.value.pagenow+=1;
            show()
        }
       
    }
    if(a==4){
        page.value.pagenow=count.value.pagecount;
        show()
    }
}
onMounted(()=>{
    show()
})
const router=useRouter()
const show=()=>{


    axios.get('https://localhost:7167/api/Hospital/Show',{params:page.value}).then(res=>{
      list.value=res.data.list
      count.value.count=res.data.count
      count.value.pagecount=Math.ceil(count.value.count/page.value.pagehang)

    })
}
const count=ref({
    count:0,
    pagecount:0
})
const page=ref({
    pagenow:1,
    pagehang:2,
    hname:""
})
const list=ref([{
    "hid": 0,
      "number": "",
      "hname": "",
      "price": 0,
      "isdel": true,
      "state": true,
      "num": 0,
      "time": 0
}])
const del=(vid:any)=>{
if(!confirm("确认删除吗")){
    return;
}

axios.get('https://localhost:7167/api/Hospital/Del',{params:{id:vid}}).then(res=>{
    if(res.data>0){
            alert('成功')
            page.value.pagenow=1;
show()
        }else{
            alert('失败')
        }

})
}
const state=()=>{


axios.get('https://localhost:7167/api/Hospital/State',{params:{idstring:ids.value.toString()}}).then(res=>{
    if(res.data>0){
            alert('成功')
           
show()
        }else{
            alert('失败')
        }

})
}
const type=ref(false)
const ids=ref([0])
const all=()=>{
if(!type.value){
    for (let index = 0; index < list.value.length; index++) {
        ids.value.push(list.value[index].hid)
        
    }
}else{
    ids.value=[0]
}

}
</script>

<style scoped>

</style>